
function Node(element){
  this.element = element;
  this.next = null;
}
function LList(){
  this.head = new Node("head");
  this.find = find;
  this.insert = insert;
  this.display = display;
  this.findPrevious = findPrevious;
  this.remove = remove;
}
function remove(item) {
  var prevNode = this.findPrevious(item);
  if (!(prevNode.next == null)) {
    prevNode.next = prevNode.next.next;
  }
}
function findPrevious(item) {
  var currNode = this.head;
  while (!(currNode.next == null) &&
    (currNode.next.element != item)) {
    currNode = currNode.next;
  }
  return currNode;
}
function display() {
  var currNode = this.head;
  var nodestr = "";
  while (!(currNode.next == null)) {
    nodestr +=" "+currNode.next.element;
    currNode = currNode.next;
  }
  console.log(nodestr);
}
function find(item) {
  var currNode = this.head;
  while (currNode.element != item) {
    currNode = currNode.next;
  }
  return currNode;
}
function insert(newElement, item) {
  var newNode = new Node(newElement);
  var current = this.find(item);
  newNode.next = current.next;
  current.next = newNode;
}
/*测试例子*/
var num = new LList();
num.insert("a1","head");
num.insert("b1","a1");
num.insert("c1","b1");
num.display();
num.remove("b1");
num.display();

//console.log("nihao "+num.element)
